import { IR } from '@/types/response';
import { mock, Random } from 'mockjs'
const prefix = import.meta.env.VITE_API_URL;
/**
 * 获取员工列表
 */
mock(/staffList\//, "get", () => {


  const res = mock({
    'list|8': [
      {
        avatar: "@img",
        email: "@email",
        'sex|1': [0, 1],
        'age|18-100': 1,
        'id|+1': 1,
        birthday: "@date",
        address: "@address",
        nickName: "@cname(2,5)",
        duties: {
          name: "用户界面/交互设计师",
          'level|1': ["低", "中", "高"],
          'schedule': function () {
            return ((Math.random() * 100) >> 0) + "%";
          }
        }
      }]
  })
  return getSuccess(res.list)
})

/**
 * 登录
 */
mock(prefix + "/user/login", "post", () => {


  const res = mock({
    "user": {
      avatar: "@img",
      email: "@email",
      'sex|1': [0, 1],
      'age|18-100': 1,
      'id|+1': 1,
      birthday: "@date",
      address: "@address",
      nickName: "@cname(2,5)",
      duties: {
        name: "用户界面/交互设计师",
        'level|1': ["低", "中", "高"],
        'schedule': function () {
          return ((Math.random() * 100) >> 0) + "%";
        }
      }
    },
    token: "@guid",
    accessToken: "@guid",
  })
  return getSuccess(res)
})

/**
 * 获取员工列表分页
 */
mock(/staffListPage/, "get", () => {

  const res = mock({
    'list|8': [
      {
        avatar: "@img",
        email: "@email",
        'sex|1': [0, 1],
        'age|18-100': 1,
        'id|+1': 1,
        birthday: "@date",
        address: "@address",
        nickName: "@cname(2,5)",
        duties: {
          name: "用户界面/交互设计师",
          'level|1': ["低", "中", "高"],
          'schedule': function () {
            return ((Math.random() * 100) >> 0) + "%";
          }
        }
      }],
    'total|100': 1
  })

  return getSuccess<{ list: Array<any>, tital: number }>(res)
})

/**
 * 最近事件 三条
 */
mock(prefix + "/event/recent", 'get', () => {
  let res = mock({
    "list|3": [{
      id: "@id",
      title: "@ctitle",
      day: "@date",
      time: "@time",
      duration: function () {
        return Random.integer(1, 3) + "h"
      },
      isRising: () => Random.boolean(),
    }]
  })
  return getSuccess(res.list)
})

/**
 * 全部事件
 */
mock(prefix + "/event/all", 'get', () => {
  let res = mock({
    "list|12": [{
      id: "@id",
      title: "@ctitle",
      day: "@date",
      time: "@time",
      duration: function () {
        return Random.integer(1, 3) + "h"
      },
      isRising: () => Random.boolean(),
      iconName: "icon-news"
    }]
  })
  return getSuccess(res.list)
})


/**
 * 最近项目 三条
 */
mock(prefix + "/project/not", 'get', () => {
  let res = mock({
    "list|3": [{
      id: "@id",
      projectId: "@id",
      title: "@ctitle",
      date: "@date",//日期
      isUp: () => Random.boolean(),//是否上升
      'level|1': ['低', "中", '高'],
      img: "@img",
      task: {
        'all|10-30': 1,
        'current|1-20': 10,
        "executor|1-10": ['@img']
      },

    }]
  })
  return getSuccess(res.list)
})
/**
 * 最近项目 三条
 */
mock(prefix + "/project/list", 'get', () => {
  let res = mock({
    "list|10-20": [{
      id: "@id",
      projectId: "@id",
      title: "@ctitle",
      date: "@date",//日期
      isUp: () => Random.boolean(),//是否上升
      'level|1': ['低', "中", '高'],
      img: "@img",
      task: {
        'all|10-30': 1,
        'current|1-20': 10,
        "executor|1-10": ['@img']
      },

    }]
  })
  return getSuccess(res.list)
})



/**
 * 获取日历
 */
mock(/getCalendar/, 'post', () => {
  let res = mock({
    "list|20": [{
      id: '@id',
      name: "@cname",
      userId: "@id",
      type: "1",
      'level|1': ["低级", "中级", "高级"],
      'date|1': ["2023-08-20", '2023-08-19', '2023-08-22'],
      time: "@time",
      descript: "@title",
      isUp: () => Random.boolean(),
    }]
  })
  return getSuccess(res.list)
})
/**
 * 获取任务
 */
mock(/task/, 'post', () => {
  let res = mock({
    "list|10-20": [
      {
        id: "@id",
        name: "@cname",
        "group|1": ["1", "2", "3"],//分组
        estimatedTime: "@date",//预估时间
        actualTime: "@date",//实际时间
        createTime: "@date",
        endTime: "@date",
        executor: {
          avatar: "@img",
          email: "@email",
          'sex|1': [0, 1],
          'age|18-100': 1,
          'id|+1': 1,
          birthday: "@date",
          address: "@address",
          nickName: "@cname(2,5)",
          duties: {
            name: "用户界面/交互设计师",
            'level|1': ["低", "中", "高"],
            'schedule': function () {
              return ((Math.random() * 100) >> 0) + "%";
            }
          }
        },
        desc: "@ctitle",
        isUp: () => Random.boolean(),//是否上升
        'level|0-2': 1,
        "status|1": ["待完成", "完成中", "已完成"],//完成状态
        'schedule': function () {
          return ((Math.random() * 100) >> 0) + "%";
        }//进度
      }
    ],

  })
  return getSuccess(res.list)
})

function getSuccess<T>(t: T) {
  const res: IR<T> = {
    code: 200,
    data: t,
    success: true,
    message: "请求成功",
  }
  return res;
}